package common.checkdatagrid
{
	import flash.display.DisplayObject;   
	import flash.events.Event;   
	import flash.text.TextField;   
	
	import mx.collections.ArrayCollection;   
	import mx.controls.Alert;   
	import mx.controls.CheckBox;

	
	public class CheckBoxIR extends CheckBox{   
		public var keyname:String="cuserId"; 
		public function CheckBoxIR(){   
			super();   
			this.addEventListener(Event.CHANGE, cgHandler);   
		}   
		
		override public function set data(value:Object) : void{   
			super.data = value;   
			
			
			if(CheckDataGrid(listData.owner).isInSelected(data))   
			{   
				this.selected = true;   
			}   
			else  
			{   
				this.selected = false;   
			}   
			
			  //Alert.show("int set data--"+data.@keyname);   
		}   
		
		
		//居中显示   
		override protected function updateDisplayList(w:Number, h:Number) : void{   
			super.updateDisplayList(w, h);   
			
			for(var i:Number=0; i<numChildren; i++)   
			{   
				var c:DisplayObject = getChildAt(i);   
				if(!(c is TextField))   
				{   
					c.x = Math.round((w-c.width)/2);   
					c.y = Math.round((h-c.height)/2);   
				}   
			}   
		}   
		
		protected function cgHandler(event:Event):void{   
			
			var dg:CheckDataGrid = CheckDataGrid(listData.owner);   
			
			if(this.selected == true)   
			{   
				dg.addToSelected(data);   
			}   
			else  
			{   
				dg.delFromSelected(data);   
			}   
		}   
		
	}   

}